﻿<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-timepicker-addon.js" type="text/javascript"></script>


@using PInitiatives.Models

@model PInitiatives.ViewModels.VMInitiative.VMInitiativeBrowse

@{
    ViewBag.Title = "Initiatives";
}


<!-- Przyciski do logowania i do rejestracji -->                           
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.")
@if (!Request.IsAuthenticated)
{
    using (Html.BeginForm())
    {


     <div class="row-fluid">
        <div class="span12">
        <div class="alert alert-success">

                <h2>Witaj na portalu ivent.pl!</h2>
<h5><i>
    Brakuje 11stego do gry w piłkę dzisiaj wieczorem?<br/>
    A może chcesz zagrać jutro paintball ale nie masz teamu? <br/>
    Albo chcesz po prostu zrobić coś nowego i ciekawego w najbliższy weekend ale nie masz pomysłu?<br/>
    <br/>
    Trafiłeś w dobre miejsce!
    <br/>
    </i>
    </h5>
    <center><h3>ivent - szybka inicjatywa!</h3></center>

</div>
                  </div>
    </div>
    



    
    <div class="row-fluid">

        <div class="span6">
        <strong>Jeśli już posiadasz konto: </strong>
            <a href="../Account/LogOn" class="btn ini-green-btn"><i class="icon-check icon-white"></i>Zaloguj się!</a>
        </div>
        <div class="span6">
            <strong> Dołącz do nas:</strong  >
            <a href="../Account/Register" class="btn ini-green-btn"><i class="icon-edit icon-white"></i>Zarejestruj się!</a>
        </div>
     
    </div>
    <br/>
            <div class="alert alert-success">

            
    <center><h3><i>I już teraz nawiąż nowe ekscytujące znajomości!</i></h3></center>

</div>
    <div class="row-fluid">
        <br/>
        <br/>
            <div style="border-bottom: 1px solid #DDD;"></div>
       <br/>
    </div>
    }
}

    <div class="row-fluid">
            <h3>Najnowsze iventy:</h3>
       <br/>

    </div>
 @if (Request.IsAuthenticated)
 {
<!-- button utwórz inicjatywę -->
<form action = "Create">    
    <button type="submit" class="btn ini-green-btn" ><i class="icon-star-empty icon-white"></i> Utwórz nowy ivent</button>
</form>
 }
<!-- editboxy do filtrów -->
<div class="row-fluid">
    <div class="span6">
        <form class="form-inline" action="Browse" method="get">
        Nazwa:<br />
        @Html.HiddenFor(model => model.category, Model.category)
        @Html.HiddenFor(model => model.status, Model.status)
        @*@Html.HiddenFor(model => model.startDateFrom, Model.startDateFrom)*@
        @Html.EditorFor(model => model.searchString)
        <button type="submit">
            <i class="icon-search"></i>
        </button>
        </form>
    </div>
    <div class="span6">
        <form class="form-inline" action="Browse" method="get">
        Status:<br />
        @Html.HiddenFor(model => model.category, Model.category)
        @Html.HiddenFor(model => model.searchString, Model.searchString)
        @*@Html.HiddenFor(model => model.startDateFrom, Model.startDateFrom)*@
        @Html.DropDownList("Status")
        <button type="submit">
            <i class="icon-search"></i>
        </button>
        </form>
    </div>
</div>
<!-- wyświetlane filtry -->
<table>
<tr>
<td>@{
    if (@Request.Params.Get("searchString") != null)
    {
        if (!@Request.Params.Get("searchString").Equals(""))
        {
            <form action = "Browse" method="get">
                @Html.HiddenFor(model => model.category, Model.category)
                @Html.HiddenFor(model => model.status, Model.status)
                @*@Html.HiddenFor(model => model.startDateFrom, Model.startDateFrom)*@
                <button class="btn btn-info btn-mini" type="submit"><i class="icon-filter icon-white"></i>  Wyświetl według nazwy:<strong> @Request.Params.Get("searchString")</strong></button>
            </form>
        }
    }
}</td>
<td>@{
    if (@Request.Params.Get("status") != null)
    {
        if (!@Request.Params.Get("status").Equals(""))
        {
            <form action = "Browse" method="get">
                 @Html.HiddenFor(model => model.category, Model.category)
                 @Html.HiddenFor(model => model.searchString, Model.searchString)
                 @*@Html.HiddenFor(model => model.startDateFrom, Model.startDateFrom)*@
                 <button class="btn btn-info btn-mini" type="submit"><i class="icon-filter icon-white"></i>  Wyświetl według statusu: <strong>@Request.Params.Get("status")</strong></button>
            </form>
        }
    }
}</td>
</tr>
</table>
@*<td>
<form action = "Browse" method="get">
    Data rozpoczęcia od:<br />
    @Html.HiddenFor(model => model.category, Model.category)
    @Html.HiddenFor(model => model.searchString, Model.searchString)

    <script type="text/javascript">
          $(document).ready(function () {
              $('.StartDTF').datetimepicker({
                  timeFormat: "hh:mm",
                  dateFormat: "yy-mm-dd",
              })
          });
    </script>                     
            @Html.TextBox("startDateFrom", DateTime.Now.ToString("yyyy-MM-dd HH:mm"), new { @class = "StartDTF" })
    <br />          
    <button type="submit">szukaj</button>
</form>

<form action = "Browse" method="get">
    @Html.HiddenFor(model => model.category, Model.category)
    @Html.HiddenFor(model => model.searchString, Model.searchString)
    <button type="submit">usuń</button>
</form>
</td>*@



@*@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Initiative</legend>
        
        <div class="editor-label">
            Nazwa:
            @Html.EditorFor(model => model.searchString)
        </div>
            @Html.HiddenFor(model => model.category, Model.category)
            @Html.HiddenFor(model => model.page, Model.page)
            @Html.HiddenFor(model => model.orderBy, Model.orderBy)
            @Html.HiddenFor(model => model.orderRule, Model.orderRule)
        <p>
            <input type="submit" value="Search" method="Get"/>
        </p>
    </fieldset>
}*@

  
@*<form action = "Browse" method="get">
    @Html.HiddenFor(model => model.category, Model.category)
    <button type="submit">pokaż wszystkie w kategorii</button>
</form>

<form action = "Browse" method="get">
    <button type="submit">pokaż wszystkie</button>
</form>*@




@{
    var browsedInitiatives = new WebGrid(
        source: Model.Initiatives,
        canPage: true,
        canSort: true,
        rowsPerPage: 10,
        defaultSort: "Name",
        ajaxUpdateContainerId: "browsedInitiativesGrid"
        );

        }


@browsedInitiatives.GetHtml(
htmlAttributes:
                        new { id = "browsedInitiativesGrid" },
                tableStyle: "ini-table-black",
                    columns: browsedInitiatives.Columns(
                            browsedInitiatives.Column(
                                    columnName: "Name",
                                    header: "Nazwa",
                                            format: item => @Html.ActionLink((string)item.Name, "Details", new { id = item.ID, category = @Model.category }, new { title = item.Description })
                            ),
                            browsedInitiatives.Column(
                                    columnName: "StartDate",
                                    header: "Data ropoczęcia"//,
                                            //format: item => @Html.Display(((DateTime)item.StartDate).ToString("yyyy-MM-dd HH:mm"), new { title = item.Description })
                            ),
                            browsedInitiatives.Column(
                                    columnName: "State",
                                    header: "Status",
                                    format: item => item.statusPL

                            ),
                            browsedInitiatives.Column(
                                    columnName: "CreateDate",
                                    header: "Data utworzenia"//,
                                    //format: item => @Html.Display(((DateTime)item.CreateDate).ToString("yyyy-MM-dd HH:mm"), new { title = item.Description })
                            ),
                            browsedInitiatives.Column(
                                    columnName: "Limit",
                                    header: "Liczba miejsc",
                                    format: item => (string)(item.Limit+ "   (" + item.usersCount + ")")
                            )
                    )


)





@*
<table>
    <tr>
        <th>
            Name
        </th>
        <th>
            Parent
        </th>
        <th>
            Liczba Inicjatyw w danej kategorii
        </th>
        <th>
            Liczba Inicjatyw w całej gałęzi
        </th>
    </tr>


@foreach (var item in Model.Categories)
{
    <tr>
        <td>
            @Html.ActionLink(item.Name, "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "category", item.ID))
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Parent)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Initiatives.Count)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CountInitaitvesInBranch)
        </td>
    </tr>
}

</table>

<table>
    <tr>
        <th>
            @Html.ActionLink("Name", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "IName"))
        </th>
        <th>
            @Html.ActionLink("Description", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "IDescription"))
        </th>
        <th>
            @Html.ActionLink("Author", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "IAuthor"))            
        </th>
        <th>
            @Html.ActionLink("Category", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "ICategory"))            
         </th>
        <th>
            @Html.ActionLink("StartDate", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "IStartDate"))            
         </th>
        <th>
            @Html.ActionLink("CreateDate", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "ICreateDate"))            
         </th>
        <th>
            @Html.ActionLink("State", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "orderBy", "IState"))            
         </th>
        <th></th>
    </tr>

@foreach (var item in Model.Initiatives)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Description)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.InitiativeAuthor.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Categories.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StartDate)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CreateDate)
        </td>
       <td>
            @Html.DisplayFor(modelItem => item.State)
        </td>
        <td>
            @if(Model.userName == item.InitiativeAuthor.aspnet_Users.UserName){
                @Html.ActionLink("Edit", "Edit", new { id = item.ID }) <b>|</b>
                @Html.ActionLink("Delete", "Delete", new { id = item.ID }) <b>|</b>
            }
            @Html.ActionLink("Details", "Details", new { id = item.ID })
        </td>
    </tr>
}
</table>

    @Html.ActionLink("Prev", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "page", Model.page - 1)) 
    @Model.page 
    @Html.ActionLink("Next", "Browse", PInitiatives.Models.Initiative.RequestToDictionary(Model, "page", Model.page + 1)) 

*@




<link href="../../Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />